<?php
session_start();
@$name = $_REQUEST["name"];
@$email = $_REQUEST["email"];
@$city = $_REQUEST["city"];
@$area = $_REQUEST["area"];
@$address = $_REQUEST["address"];
@$pin = $_REQUEST["pin"];
@$username = $_REQUEST["username"];
@$phone = $_REQUEST["phone"];
@$password = $_REQUEST["password"];
@$question = $_REQUEST["question"];
@$answer = $_REQUEST["answer"];
@$gender = $_REQUEST["gender"];
@$card_type = $_REQUEST["card_type"];
@$card_no = $_REQUEST["card_no"];
@$c_name = $_REQUEST["c_name"];
@$month = $_REQUEST["month"];
@$year = $_REQUEST["year"];
@$cvv = $_REQUEST["cvv"];
@$payment = $_REQUEST["payment"];
@$_SESSION['username'] = $username;
if ($_SESSION["username"] == true) {
    $a = mysqli_connect("localhost", "root", "deng123", "housekeeping", "3306") or die("unable to connect");
    $query = "SELECT username FROM user_details";
    @$result = mysqli_query($a, $query);
    $count = 0;
    $amount = 100;
    // b_day 填写今天的日期
    $b_day = date("Y-m-d");
    // 插入数据之前清空 credit_card 中name 与当前name一致的数据
    $clear_query = "DELETE FROM credit_card WHERE name='$name'";
    mysqli_query($a, $clear_query);
    $insert_query = "INSERT INTO credit_card (card_type, card_no, name, exp_month, exp_year, cvv,Amount,b_day) VALUES
     ('$card_type', '$card_no', '$name', '$month', '$year', '$cvv','$amount','$b_day')";
    mysqli_query($a, $insert_query);
    echo  mysqli_error($a);

?>
    <?php

    if (mysqli_error($a)) {
    ?>
        <!DOCTYPE html>
        <html>

        <head>

            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
            <meta name="description" content="">
            <meta name="author" content="">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <title>好先生 | 家政服务</title>
            <link rel="shortcut icon" href="img/favicon.ico" />
            <!-- Bootstrap core CSS -->
            <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

            <!-- Custom fonts for this template -->
            <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
            <link rel="stylesheet" href="vendor/simple-line-icons/css/simple-line-icons.css">

            <!-- Plugin CSS -->
            <link rel="stylesheet" href="device-mockups/device-mockups.min.css">

            <!-- Custom styles for this template -->
            <link href="css/style.css" rel="stylesheet">
            <link href="css/hover-min.css" rel="stylesheet">
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link href="plugins/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">


        </head>

        <body id="page-top">

            <!-- Navigation -->
            <nav class="navbar navbar-expand-lg navbar-light fixed-top bg-info" id="mainNav">
                <div class="container">
                    <div class="navbar-header">
                        <a class=" nav-link js-scroll-trigger" href="#top">
                            <img class="img-rounded" src="img/logo.png" />
                        </a>
                    </div>
                    &nbsp;
                    <a class="navbar-brand " href="#page-top">
                        <h2><small style="font-family: Arial;border-bottom: 2px solid gainsboro">服务专家</small></h2>
                    </a>
                    <button class="navbar-toggler navbar-toggler-right ml-auto" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                        菜单
                        <i class="fas fa-bars"></i>
                    </button>
                    <div class="collapse navbar-collapse" id="navbarResponsive">
                        <ul class="navbar-nav ml-auto">
                            <li class="nav-item">
                                <a class="nav-link js-scroll-trigger hvr-bounce-to-right" href="logout.php">首页</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link js-scroll-trigger hvr-bounce-to-right" href="userlogin.php">用户登录/注册</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link js-scroll-trigger hvr-bounce-to-right" href="contact.html">联系我们</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>


            <section class="features" id="features" style="background:lavender">
                <div class="container">
                    <div style="text-align: center">
                        <h1 class="mb-5 text-info" style="font-family:Catamaran;font-size: 50px;margin-top: 150px">哎呀！该银行卡号已经存在了~.
                        </h1>
                        <!-- 返回上一页 -->
                        <a href="javascript:history.back(-1);" class="btn btn-primary">返回上一页</a>

                    </div>
                    <div class="row" style="height: 70px">
                        <div class="col-sm-12 my-auto">
                            <div class="container-fluid">
                                <div class="row">

                                </div>
            </section>
            <footer>
                <div class="container">
                    <p>&copy; 好先生 家政服务. 版权所有.</p>
                    <ul class="list-inline">
                        <li class="list-inline-item">
                            <a href="#">隐私</a>
                        </li>
                        <li class="list-inline-item">
                            <a href="#">条款</a>
                        </li>
                    </ul>
                </div>
            </footer>
            <!-- Bootstrap core JavaScript -->
            <script src="vendor/jquery/jquery.min.js"></script>
            <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

            <!-- Plugin JavaScript -->
            <script src="vendor/jquery-easing/jquery.easing.min.js"></script>


            <script src="js/new-age.min.js"></script>
        </body>

        </html>
        <?php
        session_destroy(); //destroy the session
        exit();
        ?>

    <?php
    }
    ?>
    <?php
    if ($result) {
        while ($row = mysqli_fetch_array($result)) {
            $dbusername = $row['username'];
            if ($username == $dbusername) {
                $count = $count + 1;
                break;
            }
        }
        if ($count == 1) {
    ?>
            <!DOCTYPE html>
            <html>

            <head>

                <meta charset="utf-8">
                <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
                <meta name="description" content="">
                <meta name="author" content="">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <title>好先生 | 家政服务</title>
                <link rel="shortcut icon" href="img/favicon.ico" />
                <!-- Bootstrap core CSS -->
                <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

                <!-- Custom fonts for this template -->
                <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet">
                <link rel="stylesheet" href="vendor/simple-line-icons/css/simple-line-icons.css">

                <!-- Plugin CSS -->
                <link rel="stylesheet" href="device-mockups/device-mockups.min.css">

                <!-- Custom styles for this template -->
                <link href="css/style.css" rel="stylesheet">
                <link href="css/hover-min.css" rel="stylesheet">
                <meta name="viewport" content="width=device-width, initial-scale=1">
                <link href="plugins/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">


            </head>

            <body id="page-top">

                <!-- Navigation -->
                <nav class="navbar navbar-expand-lg navbar-light fixed-top bg-info" id="mainNav">
                    <div class="container">
                        <div class="navbar-header">
                            <a class=" nav-link js-scroll-trigger" href="#top">
                                <img class="img-rounded" src="img/logo.png" />
                            </a>
                        </div>
                        &nbsp;
                        <a class="navbar-brand " href="#page-top">
                            <h2><small style="font-family: Arial;border-bottom: 2px solid gainsboro">服务专家</small></h2>
                        </a>
                        <button class="navbar-toggler navbar-toggler-right ml-auto" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
                            菜单
                            <i class="fas fa-bars"></i>
                        </button>
                        <div class="collapse navbar-collapse" id="navbarResponsive">
                            <ul class="navbar-nav ml-auto">
                                <li class="nav-item">
                                    <a class="nav-link js-scroll-trigger hvr-bounce-to-right" href="logout.php">首页</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link js-scroll-trigger hvr-bounce-to-right" href="userlogin.php">用户登录/注册</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link js-scroll-trigger hvr-bounce-to-right" href="contact.html">联系我们</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </nav>


                <section class="features" id="features" style="background:lavender">
                    <div class="container">
                        <div style="text-align: center">
                            <h1 class="mb-5 text-info" style="font-family:Catamaran;font-size: 50px;margin-top: 150px">哎呀！用户名已经存在，请尝试其他名称。.
                            </h1>
                        </div>
                        <div class="row" style="height: 70px">
                            <div class="col-sm-12 my-auto">
                                <div class="container-fluid">
                                    <div class="row">

                                    </div>
                </section>
                <footer>
                    <div class="container">
                        <p>&copy; 好先生 家政服务. 版权所有.</p>
                        <ul class="list-inline">
                            <li class="list-inline-item">
                                <a href="#">隐私</a>
                            </li>
                            <li class="list-inline-item">
                                <a href="#">条款</a>
                            </li>
                        </ul>
                    </div>
                </footer>
                <!-- Bootstrap core JavaScript -->
                <script src="vendor/jquery/jquery.min.js"></script>
                <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

                <!-- Plugin JavaScript -->
                <script src="vendor/jquery-easing/jquery.easing.min.js"></script>


                <script src="js/new-age.min.js"></script>
            </body>

            </html>


            <?php
            session_destroy(); //destroy the session
            exit();
        } else {
            @$q = "SELECT * FROM credit_card Where card_no='$card_no' and card_type='$card_type' and name='$c_name' and exp_month='$month' and exp_year='$year' and cvv='$cvv'";
            @$res = mysqli_query($a, $q);
            $row = mysqli_fetch_array($res);
            $dbb_day = $row['b_day'];
            if ($res) {
                if (mysqli_num_rows($res) == 0) {
            ?>
                    <!DOCTYPE html>
                    <html lang="en">

                    <head>

                        <meta charset="utf-8">
                        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
                        <meta name="description" content="">
                        <meta name="author" content="">

                        <title>好先生 | 家政服务</title>
                        <link rel="shortcut icon" href="img/favicon.ico" />
                        <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
                        <link rel="stylesheet" type="text/css" href="css/style.css">
                        <script src="vendor/jquery/jquery.min.js"></script>
                        <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
                    </head>

                    <body>
                        <div class="container-fluid register">
                            <br>
                            <div class="row">
                                <div class="col-md-3 register-left">
                                    <img src="img/logo.png" alt="" />
                                    <h2 style="font-family: Catamaran">欢迎</h2>
                                    <?php
                                    echo "<h1>$name</h1>";
                                    ?>
                                    <br><br>
                                    <h3 style="font-family: Catamaran">信用卡详细信息将用于将来的交易，您可以随时更新.</h3>
                                </div>
                                <div class="col-md-9 register-right">
                                    <div class="tab-content" id="myTabContent">
                                        <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                                            <br>
                                            <h2 class="register-heading">无效的银行卡信息，请输入正确的.</h2>
                                            <form action="u_reg_next3.php" method="post">
                                                <div class="register-form">
                                                    <div class="row">
                                                        <div class="col-md-3"></div>
                                                        <div class="col-md-6 ">
                                                            <div class="form-group">
                                                                <select name="card_type" required="required" class="form-control">
                                                                    <option value="" selected disabled>--选择银行卡选项--</option>
                                                                    <option value="china_band">中国银行</option>
                                                                    <option value="create_band">建设银行</option>
                                                                    <option value="come_band">招商银行</option>
                                                                    <option value="nong_band">农商银行</option>
                                                                </select>
                                                            </div>
                                                            <div class="form-group">
                                                                <input type="number" name="card_no" class="form-control" placeholder="卡号 *" required />
                                                            </div>
                                                            <div class="form-group">
                                                                <input type="text" name="c_name" class="form-control" placeholder="银行卡上的名字*" required />
                                                            </div>
                                                            <div class="form-group">
                                                                到期日期*&nbsp;
                                                                <div class="row">
                                                                    <div class="col-6">
                                                                        <select name="month" required="required" class="form-control">
                                                                            <option value="" selected disabled>--选择月--</option>
                                                                            <option>1</option>
                                                                            <option>2</option>
                                                                            <option>3</option>
                                                                            <option>4</option>
                                                                            <option>5</option>
                                                                            <option>6</option>
                                                                            <option>7</option>
                                                                            <option>8</option>
                                                                            <option>9</option>
                                                                            <option>10</option>
                                                                            <option>11</option>
                                                                            <option>十2</option>
                                                                        </select>
                                                                    </div>
                                                                    <div class="col-6">
                                                                        <select name="year" required="required" class="form-control">
                                                                            <option value="" selected disabled>--选择年--</option>
                                                                            <option>2018</option>
                                                                            <option>2019</option>
                                                                            <option>2020</option>
                                                                            <option>2021</option>
                                                                            <option>2022</option>
                                                                            <option>2023</option>
                                                                            <option>2024</option>
                                                                            <option>2025</option>
                                                                        </select>
                                                                    </div>
                                                                </div>
                                                            </div>

                                                            <div class="form-group">
                                                                <input type="number" name="cvv" class="form-control" placeholder="输入银行卡安全码*" value="" required="" />
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <input type="hidden" name="name" value="<?php echo $name; ?>">
                                                    <input type="hidden" name="email" value="<?php echo $email; ?>">
                                                    <input type="hidden" name="city" value="<?php echo $city; ?>">
                                                    <input type="hidden" name="area" value="<?php echo $area; ?>">
                                                    <input type="hidden" name="address" value="<?php echo $address; ?>">
                                                    <input type="hidden" name="pin" value="<?php echo $pin; ?>">
                                                    <input type="hidden" name="username" value="<?php echo $username; ?>">
                                                    <input type="hidden" name="phone" value="<?php echo $phone; ?>">
                                                    <input type="hidden" name="password" value="<?php echo $password; ?>">
                                                    <input type="hidden" name="question" value="<?php echo $question; ?>">
                                                    <input type="hidden" name="answer" value="<?php echo $answer; ?>">
                                                    <input type="hidden" name="gender" value="<?php echo $gender; ?>">
                                                    <input type="hidden" name="payment" value="<?php echo $payment; ?>">
                                                    <div class="row">
                                                        <div class="col-md-1"></div>
                                                        <div class="col-md-7">
                                                            <div class="form-group">
                                                                <input type="submit" class="btnRegister" value="下一步 >>" />
                                                            </div>

                                                        </div>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <footer>
                            <div class="container">
                                <p>&copy; 好先生 家政服务. 版权所有.</p>
                                <ul class="list-inline">
                                    <li class="list-inline-item">
                                        <a href="#">隐私</a>
                                    </li>
                                    <li class="list-inline-item">
                                        <a href="#">条款</a>
                                    </li>
                                </ul>
                            </div>
                        </footer>
                    </body>

                    </html>
                <?php
                } else {
                ?>
                    <!DOCTYPE html>
                    <html lang="en">

                    <head>

                        <meta charset="utf-8">
                        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
                        <meta name="description" content="">
                        <meta name="author" content="">

                        <title>好先生 | 家政服务</title>
                        <link rel="shortcut icon" href="img/favicon.ico" />
                        <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
                        <link rel="stylesheet" type="text/css" href="css/style.css">
                        <script src="vendor/jquery/jquery.min.js"></script>
                        <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
                    </head>

                    <body>
                        <div class="container-fluid register">
                            <br>
                            <div class="row">
                                <div class="col-md-3 register-left">
                                    <img src="img/logo.png" alt="" />
                                    <h2 style="font-family: Catamaran">欢迎</h2>
                                    <?php
                                    echo "<h1>$name</h1>";
                                    ?>
                                    <br><br>
                                    <h3 style="font-family: Catamaran">提供安全密钥以验证持卡人并完成注册</h3>
                                </div>
                                <div class="col-md-9 register-right">
                                    <div class="tab-content" id="myTabContent">
                                        <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">
                                            <br>
                                            <h2 class="register-heading">验证持卡人</h2>
                                            <form action="u_reg_logic.php" method="post">
                                                <div class="register-form">
                                                    <div class="row">
                                                        <div class="col-md-3"></div>
                                                        <div class="col-md-6 ">
                                                            <div class="form-group">
                                                                <input type="text" class="form-control" placeholder="持卡人的出生日期是哪一天? " readonly />
                                                            </div>
                                                            <div class="form-group">
                                                                <input type="date" name="ans" class="form-control" required />
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <input type="hidden" name="name" value="<?php echo $name; ?>">
                                                    <input type="hidden" name="email" value="<?php echo $email; ?>">
                                                    <input type="hidden" name="city" value="<?php echo $city; ?>">
                                                    <input type="hidden" name="area" value="<?php echo $area; ?>">
                                                    <input type="hidden" name="address" value="<?php echo $address; ?>">
                                                    <input type="hidden" name="pin" value="<?php echo $pin; ?>">
                                                    <input type="hidden" name="username" value="<?php echo $username; ?>">
                                                    <input type="hidden" name="phone" value="<?php echo $phone; ?>">
                                                    <input type="hidden" name="password" value="<?php echo $password; ?>">
                                                    <input type="hidden" name="question" value="<?php echo $question; ?>">
                                                    <input type="hidden" name="answer" value="<?php echo $answer; ?>">
                                                    <input type="hidden" name="gender" value="<?php echo $gender; ?>">
                                                    <input type="hidden" name="card_no" value="<?php echo $card_no; ?>">
                                                    <input type="hidden" name="b_day" value="<?php echo $dbb_day; ?>">
                                                    <input type="hidden" name="payment" value="<?php echo $payment; ?>">
                                                    <div class="row">
                                                        <div class="col-md-1"></div>
                                                        <div class="col-md-7">
                                                            <div class="form-group">
                                                                <input type="submit" class="btnRegister" value="完成注册" />
                                                            </div>

                                                        </div>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                        <footer>
                            <div class="container">
                                <p>&copy; 好先生 家政服务. 版权所有.</p>
                                <ul class="list-inline">
                                    <li class="list-inline-item">
                                        <a href="#">隐私</a>
                                    </li>
                                    <li class="list-inline-item">
                                        <a href="#">条款</a>
                                    </li>
                                </ul>
                            </div>
                        </footer>
                    </body>

                    </html>
<?php
                }
            } else {
                echo "Sorry Error";
                session_destroy(); //destroy the session
                exit();
            }
        }
    } else {
        echo "Sorry Error";
        session_destroy(); //destroy the session
        exit();
    }
} else {
    header("location:u_reg.php");
}

?>